home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
10,000 Great Games
/
10,000 Great Games.iso
/
Product
/
66
/
data1.cab
/
Source_Files
/
Src
/
Turret.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-16
|
3KB
|
113 lines
#include "stdafx.h"
cTurret::cTurret(int _x, int _y, cProperties *_orig)
: cWeapon(_x, _y, _orig, "MOVING")
{
orig->get_sequence("MOVING", moving_seq);
orig->get_sequence("FIRE", fire_seq);
orig->get_spots("FIRE", &fire_spot);
rotation_speed = orig->params->get_fix("*ROTATION_SPEED", TURRET_ROT_SPEED);
rotation_start = orig->params->get_fix("*ROTATION_START", 0);
rotation_end = orig->params->get_fix("*ROTATION_END", 256);
fire_delay = orig->params->get_fix("*FIRE_DELAY", TURRET_FIRE_DLY) * sec;
rotation_direction = 1;
}
cTurret::~cTurret()
{
// Delete internal stuff
fire_spot->delete_list();
// Create explosions around turret
cEffect::make(x, y, orig, "EXPLOSIONS", 5+rnd(5), width() / 2, height() / 2);
}
void cTurret::load(cParse *list)
{
cWeapon::load(list);
rotation_speed = list->get_fix("ROTATION_SPEED", rotation_speed);
rotation_start = list->get_int("ROTATION_START", rotation_start);
rotation_end = list->get_int("ROTATION_END", rotation_end);
fire_delay = list->get_fix("FIRE_DELAY", (fix)fire_delay / sec) * sec;
armor = list->get_int("ARMOR", armor);
set_rotation_angle(rotation_start);
}
void cTurret::save()
{
cWeapon::save();
save_level_fix("ROTATION_SPEED", rotation_speed);
save_level_int("ROTATION_START", rotation_start);
save_level_int("ROTATION_END", rotation_end);
save_level_fix("FIRE_DELAY", (fix)fire_delay / sec);
save_level_int("ARMOR", armor);
}
int cTurret::control()
{
// Check explode
if (explode)
return FALSE;
// Move
cWeapon::control();
// Set animation
if (animation_done())
set_sequence(moving_seq, TRUE);
// Do rotation
set_rotation_angle(get_rotation_angle() + rotate.delta() * rotation_direction * rotation_speed);
if (rotation_end - rotation_start < (fix)256)
{
if (rotation_direction > (fix)0 && get_rotation_angle() > rotation_end)
{
rotation_direction = -1;
set_rotation_angle(rotation_end);
}
if (rotation_direction < (fix)0 && get_rotation_angle() < rotation_start)
{
rotation_direction = 1;
set_rotation_angle(rotation_start);
}
}
// Fire?
if (!firing)
{
int rx = x + fire_spot->get_rotated_x(get_rotation_angle()),
ry = y - fire_spot->get_rotated_y(get_rotation_angle());
new cBullet (rx, ry, get_rotation_angle(), this);
set_sequence(fire_seq);
new cEffect (rx, ry, orig, "FIRE EFFECT");
firing = fire_delay;
}
// Check if still on screen
return !below_screen();
}
void cTurret::create_editables(int select)
{
new cEditableTurret(this, select);
}